import org.springframework.cloud.contract.spec.Contract

Contract.make {
    request {
        method "POST"
        urlPath("/api/register")
        body("""
            {
                "username":"mahuan",
                "password":1234,
                "email":"1920374@zhangsan.com",
                "mobilePhone":"12738475645"
            }
        """)
        bodyMatchers {
            jsonPath('$.username', byRegex("\\w+"))
            jsonPath('$.password', byRegex(number()))
            jsonPath('$.email', byRegex(email()))
            jsonPath('$.mobilePhone',byRegex(number()))
        }
        headers {
            header("Content-Type", "application/json;charset=UTF-8")
        }

    }
    response {
        status 201
        body("""{
                "id":"1"
                }
            """)
        bodyMatchers {
            jsonPath('$.id', byRegex(number()))
        }
        headers {
            header("Content-Type", "application/json;charset=UTF-8")
        }
    }
}